<template>
	<view>
		<u-navbar :background="{'background-image': 'linear-gradient(to right, #434AD8, #8E77F5)'}" backIconColor="#fff" title="选择城市"
			titleColor="#fff" :borderBottom="false">
			<!-- <view class="search">
				<u-input v-model="search" placeholder="请输入搜索内容" class="input" />
				<u-icon name="search" color="#ffffff" size="40"></u-icon>
			</view> -->
		</u-navbar>

		<view class="content">
			<view class="block">
				<view class="title">定位城市</view>
				<get-location-city @location-region='clickRegion'></get-location-city>
			</view>
			<view class="block">
				<view class="title">当前城市</view>
				<view class="city">
					<view class="item" @click="clickRegion(currentRegion)">{{ currentRegion.name }}</view>
				</view>
			</view>
			<view class="block">
				<view class="title">热门城市</view>
				<view class="city">
					<view class="item" v-for="(item, index) in listData" :key='index' @click="clickRegion(item)">{{ item.name }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getRegionList
	} from '../../api/platform/goods.js'
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		data() {
			return {
				search: '',
				listData: []
			}
		},
		computed: {
			...mapState(['currentRegion'])
		},
		onLoad() {
			this.init()
		},
		methods: {
			...mapMutations(['setCurrentRegion']),
			clickRegion(region) {
				this.setCurrentRegion({
					currentRegion: region
				})
				this.getOpenerEventChannel().emit('regionChange')
				uni.navigateBack()
			},
			async init() {
				// let that = this
				// uni.getStorage({
				// 	key: 'currentRegion',
				// 	success(res) {
				// 		that.currentRegion = res.data
				// 	}
				// })
				this.listData = await getRegionList()
			}
		},
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>

<style lang="scss" scoped>
	.search {
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		background: #8586E6;
		color: white;
		border-radius: 32rpx;
		margin-right: 30rpx;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.input {
			color: white;
			margin-right: 10rpx;
		}
	}

	.content {
		padding: 10rpx 40rpx;
		height: 100%;

		.block {
			font-size: 28rpx;

			.title {
				color: #999999;
				margin: 20rpx 0;
			}

			.city {
				display: flex;
				flex-wrap: wrap;
				align-items: center;

				.item {
					min-width: 162rpx;
					line-height: 56rpx;
					text-align: center;
					border: 1px solid #ECECEC;
					border-radius: 32rpx;
					background-color: #ECECEC;
					margin-bottom: 20rpx;
					margin-right: 20rpx;
					padding: 0rpx 50rpx;
				}
				.item:hover {
					background-color: #bdbdbd;
				}
			}
		}
	}
</style>
